import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"

enum Api {
  list = "/infra-service/codeTemplateGroup/listGroup",
  save = "/infra-service/codeTemplateGroup/saveGroup",
  edit = "/infra-service/codeTemplateGroup/updateGroup",
  get = "/infra-service/codeTemplateGroup/getGroup",
  delete = "/infra-service/codeTemplateGroup/deleteGroup",
  deleteBatch = "/infra-service/codeTemplateGroup/batchDeleteGroup",
}

/**
 * 查询模板组
 * @param params
 */
export const listTemplateGroup = (params) => {
  return defHttp.get({ url: Api.list, params })
}

/**
 * 保存或者更新模板组
 * @param params
 */
export const saveOrUpdateTemplate = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save
  return defHttp.post({ url: url, params })
}

/**
 * 删除模板组
 * @param params
 */
export const deleteTemplateGroup = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

/**
 * 批量删除模板组
 * @param params
 */
export const batchDeleteTemplateGroup = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}
